package net.ds0101.FindTen;

import net.ds0101.framework.android.neox.action.NXAction;
import net.ds0101.framework.android.neox.action.NXFadeOut;
import net.ds0101.framework.android.neox.action.NXRepeatForever;
import net.ds0101.framework.android.neox.main.NXDirector;
import net.ds0101.framework.android.neox.main.NXScene;
import net.ds0101.framework.android.neox.util.NXResourceConverter;
import net.ds0101.framework.android.neox.widget.NXSprite;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.MotionEvent;

public class LogoScene extends NXScene {
	private NXSprite mBackground;
	private NXSprite mLogo;
	private NXSprite mStartDesc;
	private final static int VOFFSET = 40;
	private NXAction mRepeatFlash;
	private MainMenu mMainMenu;
	
	public LogoScene(Context context) {
		super(context);
		mMainMenu = new MainMenu(context);
		Bitmap logo = NXResourceConverter.getBitmapFromResource(this, R.drawable.logo);
		Bitmap startDesc = NXResourceConverter.getBitmapFromResource(this, R.drawable.desc01);
		backgroundBitmap(NXResourceConverter.getBitmapFromResource(this, R.drawable.blackboard));
		
		if (null != logo) {
			mLogo = NXSprite.spriteWithBitmap(logo);
			mLogo.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 3);
			addChild(mLogo);
		}
		
		if (null != startDesc) {
			mStartDesc = NXSprite.spriteWithBitmap(startDesc);
			mStartDesc.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 2 + VOFFSET);
			addChild(mStartDesc);
			mRepeatFlash = new NXRepeatForever(NXFadeOut.action(1000));
		}
    }
	
	@Override
	public void onEnter() {
		super.onEnter();
		mStartDesc.runAction(mRepeatFlash);
	}

    /*public void _onEnter() {
    	 Bitmap logo = NXResourceConverter.getBitmapFromResource(this, R.drawable.logo);
    	 Bitmap startDesc = NXResourceConverter.getBitmapFromResource(this, R.drawable.desc01);
    	 backgroundBitmap(NXResourceConverter.getBitmapFromResource(this, R.drawable.blackboard));
    	 
    	 if (null != logo) {
    		 mLogo = NXSprite.spriteWithBitmap(logo);
    		 mLogo.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 3);
    		 addChild(mLogo);
    	 }
    	 
    	 if (null != startDesc) {
    		 mStartDesc = NXSprite.spriteWithBitmap(startDesc);
    		 mStartDesc.position(NXDirector.getScreenWidth() / 2, NXDirector.getScreenHeight() / 2 + VOFFSET);
    		 addChild(mStartDesc, 10001);
    		 mRepeatFlash = new NXRepeatForever(NXFadeOut.action(1000));
    		 mStartDesc.runAction(mRepeatFlash);
    	 }
    }*/
    
	@Override
    public void onLeave() {
		super.onLeave();
    	mStartDesc.stopAction(mRepeatFlash);
    }
    
	@Override
	public void onScreenSizeChanged(int arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(int arg0) {
		// TODO Auto-generated method stub
		
	}
	
	public boolean onTouchEvent(MotionEvent event) {
		boolean ret = super.onTouchEvent(event);
		//director().pushScene(mMainMenu);
		director().replaceWithScene(mMainMenu);
		((MainEntry) director()).addAdsViewBottom();
		return ret;
	}
}